<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>在线考试系统 - 教师主页</title>
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="/css/all.min.css">
    <style>
        :root {
            --primary: #4361ee;
            --secondary: #3f37c9;
            --teacher-accent: #4361ee;
            --card-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
            --transition: all 0.3s ease;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #f5f7fb;
            color: #333;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }

        /* 导航栏样式 */
        .navbar {
            background: linear-gradient(135deg, var(--primary), var(--secondary));
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            padding: 0.8rem 1rem;
        }

        .navbar-brand {
            font-weight: 700;
            font-size: 1.5rem;
            display: flex;
            align-items: center;
        }

        .navbar-brand i {
            margin-right: 10px;
            font-size: 1.8rem;
        }

        .nav-link {
            color: rgba(255, 255, 255, 0.85) !important;
            font-weight: 500;
            padding: 0.5rem 1rem !important;
            border-radius: 4px;
            margin: 0 3px;
            transition: var(--transition);
        }

        .nav-link:hover, .nav-link.active {
            background-color: rgba(255, 255, 255, 0.15);
            color: white !important;
        }

        /* 主内容区域 */
        .main-content {
            flex: 1;
            padding: 2rem 0;
        }

        .welcome-section {
            background: white;
            border-radius: 15px;
            padding: 1.5rem;
            box-shadow: var(--card-shadow);
            margin-bottom: 2rem;
            position: relative;
            overflow: hidden;
        }

        .welcome-section::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 5px;
            height: 100%;
            background-color: var(--teacher-accent);
        }

        .welcome-title {
            font-weight: 700;
            margin-bottom: 0.5rem;
        }

        .welcome-text {
            color: #6c757d;
            margin-bottom: 0;
        }

        /* 功能卡片 */
        .card {
            border: none;
            border-radius: 12px;
            box-shadow: var(--card-shadow);
            transition: var(--transition);
            height: 100%;
            overflow: hidden;
        }

        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
        }

        .card-header {
            background: white;
            border-bottom: 1px solid rgba(0, 0, 0, 0.05);
            padding: 1.25rem 1.5rem;
            font-weight: 700;
            display: flex;
            align-items: center;
        }

        .card-header i {
            margin-right: 10px;
            font-size: 1.25rem;
            color: var(--teacher-accent);
        }

        .card-body {
            padding: 1.5rem;
        }

        .card-title {
            font-weight: 700;
            margin-bottom: 0.75rem;
        }

        .card-text {
            color: #6c757d;
            margin-bottom: 1.5rem;
        }

        .btn-primary {
            background: linear-gradient(135deg, var(--teacher-accent), #3a0ca3);
            border: none;
            padding: 0.5rem 1.5rem;
            font-weight: 600;
            border-radius: 8px;
            transition: var(--transition);
        }

        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(67, 97, 238, 0.4);
        }

        /* 统计数据样式 */
        .stat-number {
            font-size: 2.2rem;
            font-weight: 700;
            line-height: 1;
            color: var(--teacher-accent);
        }

        /* 页脚样式 */
        .footer {
            background: linear-gradient(135deg, var(--primary), var(--secondary));
            color: white;
            padding: 2rem 0;
            margin-top: auto;
        }

        .teacher .footer {
            background: linear-gradient(135deg, var(--teacher-accent), #3a0ca3);
        }

        .footer-title {
            font-weight: 700;
            margin-bottom: 1rem;
            font-size: 1.25rem;
        }

        .footer-links {
            list-style: none;
            padding: 0;
        }

        .footer-links li {
            margin-bottom: 0.5rem;
        }

        .footer-links a {
            color: rgba(255, 255, 255, 0.8);
            text-decoration: none;
            transition: var(--transition);
        }

        .footer-links a:hover {
            color: white;
            text-decoration: underline;
        }

        .social-icons {
            display: flex;
            gap: 15px;
            margin-top: 1rem;
        }

        .social-icons a {
            color: white;
            font-size: 1.5rem;
            transition: var(--transition);
        }

        .social-icons a:hover {
            transform: translateY(-3px);
        }

        .copyright {
            text-align: center;
            padding-top: 1.5rem;
            margin-top: 1.5rem;
            border-top: 1px solid rgba(255, 255, 255, 0.1);
            color: rgba(255, 255, 255, 0.7);
            font-size: 0.9rem;
        }

        /* 响应式调整 */
        @media (max-width: 768px) {
            .navbar-brand {
                font-size: 1.2rem;
            }

            .welcome-section {
                padding: 1rem;
            }

            .stat-number {
                font-size: 1.8rem;
            }
        }
    </style>
</head>
<body>
<!-- 导航栏 -->
<nav class="navbar navbar-expand-lg navbar-dark">
    <div class="container">
        <a class="navbar-brand" href="#">
            <i class="fas fa-chalkboard-teacher"></i>在线考试系统
        </a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav me-auto">
                <li class="nav-item">
                    <a class="nav-link active" href="/home/manage"><i class="fas fa-home"></i> 主页</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/exam/manage"><i class="fas fa-tasks"></i> 考试管理</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/teacher/question/manage"><i class="fas fa-book"></i> 题库管理</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/teacher/score/analysis"><i class="fas fa-chart-bar"></i> 成绩分析</a>
                </li>
            </ul>

            <ul class="navbar-nav ms-auto">
                <li class="nav-item">
                    <a class="nav-link" href="/teacher/profile">
                        <i class="fas fa-user-circle"></i> 个人信息
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/logout">
                        <i class="fas fa-sign-out-alt"></i> 退出登录
                    </a>
                </li>
            </ul>
        </div>
    </div>
</nav>

<!-- 主内容区域 -->
<div class="main-content">
    <div class="container">
        <div class="welcome-section">
            <div class="d-flex justify-content-between align-items-center">
                <div>
                    <h2 class="welcome-title">欢迎回来，<span id="teacherName" th:text="${homeData != null ? homeData.realName : '教师'}">教师</span></h2>
                    <p class="welcome-text">您已创建 <span id="totalExams" th:text="${homeData != null ? homeData.totalExams : 0}">0</span> 场考试，当前题库题目数：<span id="questionCount" th:text="${homeData != null ? homeData.questionCount : 0}">0</span></p>
                </div>
                <div class="text-center">
                    <div class="stat-number" id="pendingExams" th:text="${homeData != null ? homeData.pendingExams : 0}">0</div>
                    <small>待批改考试</small>
                    <div class="mt-2">
                        <a href="/exam/pending" class="btn btn-warning btn-sm">
                            <i class="fas fa-edit me-1"></i>查看待批改
                        </a>
                    </div>
                </div>
            </div>
        </div>

        <div class="row justify-content-center">
            <div class="col-lg-4 col-md-6 mb-4 d-flex">
                <div class="card flex-fill" style="min-width:320px;min-height:260px;">
                    <div class="card-header">
                        <i class="fas fa-tasks"></i> 考试管理
                    </div>
                    <div class="card-body" style="padding:2.2rem 1.5rem;">
                        <h5 class="card-title">考试管理</h5>
                        <p class="card-text">创建和管理考试</p>
                        <p class="text-muted small">最近创建：<span th:text="${homeData != null ? homeData.latestExamName : '-'}">-</span></p>
                        <a href="/exam/manage" class="btn btn-primary">进入管理</a>
                    </div>
                </div>
            </div>
            <div class="col-lg-4 col-md-6 mb-4 d-flex">
                <div class="card flex-fill" style="min-width:320px;min-height:260px;">
                    <div class="card-header">
                        <i class="fas fa-book"></i> 题库管理
                    </div>
                    <div class="card-body" style="padding:2.2rem 1.5rem;">
                        <h5 class="card-title">题库管理</h5>
                        <p class="card-text">管理试题库</p>
                        <p class="text-muted small">题库题目：<span id="questionCountCard" th:text="${homeData != null ? homeData.questionCount : 0}">0</span>道</p>
                        <a href="/teacher/question/manage" class="btn btn-primary">进入管理</a>
                    </div>
                </div>
            </div>
            <div class="col-lg-4 col-md-6 mb-4 d-flex">
                <div class="card flex-fill" style="min-width:320px;min-height:260px;">
                    <div class="card-header">
                        <i class="fas fa-chart-bar"></i> 成绩分析
                    </div>
                    <div class="card-body" style="padding:2.2rem 1.5rem;">
                        <h5 class="card-title">成绩分析</h5>
                        <p class="card-text">查看考试成绩分析</p>
                        <p class="text-muted small">点击进入可查看数据大屏</p>
                        <a href="/teacher/score/analysis" class="btn btn-primary">查看分析</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 页脚 -->
<footer class="footer">
    <div class="container text-center py-4">
        <a href="https://gitee.com/sorrymaker04/onlineexam-workload" target="_blank"><i class="fab fa-github fa-2x"></i></a>
        <div class="copyright mt-2">
            &copy; 2025 版权所有 北城在线考试系统小组 12 Team
        </div>
    </div>
</footer>

<!-- Bootstrap JS -->
<script src="/js/bootstrap.bundle.min.js"></script>

<script>
    // 页面加载完成后，如果没有后端数据，则通过AJAX获取
    document.addEventListener('DOMContentLoaded', function() {
        // 检查是否有后端数据
        const teacherName = document.getElementById('teacherName').textContent;
        const totalExams = document.getElementById('totalExams').textContent;
        
        // 如果数据是默认值，则通过AJAX获取
        if (teacherName === '教师' && totalExams === '0') {
            loadHomeData();
        }
    });

    // 加载首页数据（AJAX备选方案）
    function loadHomeData() {
        fetch('/teacher/home/data')
            .then(response => {
                if (!response.ok) {
                    throw new Error('网络响应错误');
                }
                return response.json();
            })
            .then(data => {
                if (data) {
                    // 更新页面数据
                    document.getElementById('teacherName').textContent = data.realName || '教师';
                    document.getElementById('totalExams').textContent = data.totalExams || 0;
                    document.getElementById('questionCount').textContent = data.questionCount || 0;
                    document.getElementById('pendingExams').textContent = data.pendingExams || 0;
                    document.getElementById('questionCountCard').textContent = data.questionCount || 0;
                }
            })
            .catch(error => {
                console.error('加载数据失败:', error);
                // 保持默认值
            });
    }
</script>
</body>
</html> 